package com.tinyseed.hmxx.admin.system.repository;

import com.tinyseed.hmxx.admin.system.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

/**
 * @version Revision 1.0.0
 * @版权：
 * @author: Howard
 * @email:
 * @see:
 * @创建日期：2020/2/27
 * @功能说明：用户查询
 * @begin
 * @修改记录:
 * @修改后版本 修改人        修改内容
 * @2020/2/27 wuxiran        创建
 * @end
 */
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor {

    User findByUsername(String username);

    User findByEmail(String email);

    @Modifying
    @Query(value = "update user set password = ?2 , last_password_reset_time = ?3 where username = ?1", nativeQuery = true)
    void updatePass(String username, String pass, Date lastPasswordResetTime);

    @Modifying
    @Query(value = "update user set email = ?2 where username = ?1", nativeQuery = true)
    void updateEmail(String username, String email);
}
